import Vue from 'vue'
import VueRouter from 'vue-router'
import Main from '../views/Main'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push (location) {

return originalPush.call(this, location).catch(err => err)

}


const routes = [
  {
    path:'/',
    redirect: "/main"
  },
  //后台管理
  {
    path: '/main',
    name: 'main',
    component: Main,
    children:[
      {
        path:'/main',
        redirect: "/main/tongji"
      },
      {
        path:'tongji',
        name:'tongji',
        component: ()=>import ('../views/Main/Tongji')
      },
      {
        path:'fupin',
        name:'fupin',
        component: ()=>import ('../views/Main/FuPin')
      },
      {
        path:'yonghu',
        name:'yonghu',
        component: ()=>import ('../views/Main/YongHu')
      },
      {
        path:'zhiyuanze',
        name:'zhiyuanze',
        component: ()=>import ('../views/Main/ZhiYuanZe')
      },
      {
        path:'liuyanban',
        name:'liuyanban',
        component: ()=>import ('../views/Main/LiuYanBan')
      },
      {
        path:'lunbotu',
        name:'lunbotu',
        component: ()=>import ('../views/Main/LunBoTu')
      },
      {
        path:'pinkunhu',
        name:'pinkunhu',
        component: ()=>import ('../views/Main/PinKunHu')
      },
      {
        path:'shoucang',
        name:'shoucang',
        component: ()=>import ('../views/Main/ShouCang')
      },
    ],
  },
  //登录
  {
    path:'/login',
    name:'login',
    component:()=>import ('../views/Login')
  },
  //前台页面
  {
    path:'/frontmain',
    name:'frontmain',
    component:()=>import ('../views/FrontMain'),
    children:[
      {
        path:'/frontmain',
        redirect:'/frontmain/fhome'
      },
      {
        path:'fhome',
        name:'fhome',
        component:()=>import ('../views/FrontMain/Home')
      },
      {
        path:'fpinkunhu',
        name:'fpinkunhu',
        component:()=>import ('../views/FrontMain/PinKunHu')
      },
      {
        path:'fzhiyuanzhe',
        name:'fzhiyuanzhe',
        component:()=>import ('../views/FrontMain/ZhiYuanZhe')
      },
      {
        path:'ffupin',
        name:'ffupin',
        component:()=>import ('../views/FrontMain/FuPin')
      },
      {
        path:'fgrzx',
        name:'fgrzx',
        component:()=>import ('../views/FrontMain/YongHuZhongXin')
      },
      {
        path:'fliuyan',
        name:'fliuyan',
        component:()=>import ('../views/FrontMain/LiuYan')
      },
      {
        path:'fpinkunhu/pkhinfo/:id',
        name:'pkhinfo',
        component:()=>import ('../views/FrontMain/PinKunHu/PinKunHuInfo')
      },
      {
        path:'fzhiyuanzhe/zyzinfo/:id',
        name:'zyzinfo',
        component:()=>import ('../views/FrontMain/ZhiYuanZhe/ZhiYuanZeInfo')
      },
      {
        path:'fzhiyuanzhe/zyzyp',
        name:'zyzyp',
        component:()=>import ('../views/FrontMain/ZhiYuanZhe/ZhiYuanZeYingPin')
      },
      {
        path:'ffupin/fpinfo/:id',
        name:'fpinfo',
        component:()=>import ('../views/FrontMain/FuPin/FuPinInfo')
      },

    ]
  }
]

const router = new VueRouter({
  mode:"history",
  routes
})

// router.beforeEach((to, from, next) => {
//   let token = window.sessionStorage.getItem('token')
//   let user = JSON.parse(window.sessionStorage.getItem('user'))
//     if(to.path != '/login'){
//       if(token==null){
//         next('/login')
//       }else{
//         if(to.path.indexOf('/main') != -1){
//           user.role == 'user' ? next('/frontmain') : next()
//         }
//         next()
//       }
//     }
//     next()
// })
export default router
